//- Copyright (c) 2016 Lucky Byte, Inc.
extends layout

append scripts
  script(src="/js/message.js")

block content
  .ui.grid.nolayout(style="margin-left:10px; margin-top:10px;")
    .column.three.wide
      .ui.raised.segment.brown
        .ui.label.ribbon.large.brown
          i.icon.calendar
          | 时间区间
        form.ui.form.small#date_form(style="margin-top:10px;"
          action="/message" method="post")
          input(type="hidden" name="user" value="#{user || ''}")
          .field
            .ui.calendar.datetime#start_time(
              data-maxdate="#{today()}"
              data-end-with="#end_time")
              .ui.input.left.icon
                i.calendar.icon
                input(type="text" name="start_time" placeholder="起始时间"
                  value="#{start_time || ''}")
          .field
            .ui.calendar.datetime#end_time(
              data-maxdate="#{today()}"
              data-start-with="#start_time")
              .ui.input.left.icon.search
                i.calendar.icon
                input(type="text" name="end_time" placeholder="截止时间"
                  value="#{end_time || ''}")
          .field
            .ui.buttons.fluid.small
              button.ui.button.grey#clear(type="button") 清空日期
              .or
              button.ui.button.green(type="submit") 查 询

      .ui.raised.segment.pink
        .ui.label.ribbon.large.pink
          i.icon.users
          | 选择用户
        .ui.divided.relaxed.small.middle.aligned.list
          .item
            i.icon.users
            .content.middle.aligned
              a#user_filter 所有用户
          each user in users
            .item
              .right.floated.content
                .ui.label.small(
                  style="padding:6px; padding-top:2px; padding-bottom:3px;")
                  | #{user.n_messages}
              i.icon.user(style="padding-top:2px;")
              .content(style="padding-top:2px;")
                a#user_filter(data-user="#{user.uuid}")= user.realname

    .column.thirteen.wide
      .ui.comments(style="max-width:1400px;")
        each record in records
          .comment
            .avatar
              i.big.icons
                if record.recver == userinfo.uuid
                  if record.status == 1
                    i.icon.comment.outline.green
                  else
                    i.icon.comment.outline
                else
                  if record.status == 1
                    i.icon.comment.outline.green
                    i.corner.icon.arrow.right.green
                  else
                    i.icon.comment.outline
                    i.corner.icon.arrow.right
            .content
              a.author
                if record.recver == userinfo.uuid
                  | #{record.send_user} 
                  i.icon.long.arrow.right.grey
                  | 我
                else
                  | 我 
                  i.icon.long.arrow.right.grey
                  | #{record.recv_user} 
              .metadata
                .date= record.time.format('YYYY-MM-DD HH:mm:ss')
                case record.status
                  when 1
                    span 未读
                  when 2
                    span 已阅
                  default
                    span 未知
              .text= record.message

              .actions
                if record.recver == userinfo.uuid && record.status == 1
                    a#message_read(data-serial="#{record.serial}"
                      data-recver="#{record.recver}") 标为已读
                a#delete(data-serial="#{record.serial}"
                  data-recver="#{record.recver}") 删除
                if record.recver == userinfo.uuid
                    a#reply(data-serial="#{record.serial}"
                      data-recver="#{record.recver}") 回复

              if record.recver == userinfo.uuid
                form.ui.form.small#message(action="/message/new" method="post"
                  style="margin-top: 10px; margin-bottom: 20px;")
                  input(type="hidden" name="user" value="#{record.sender || ''}")
                  input(type="hidden" name="redirect" value="message")
                  .field.sixteen.wide
                    textarea(name="message" type="text" rows="3" sytle="font-size:small;"
                      placeholder="留言内容仅在目标用户登录后才能看到")
                  .field
                    button.ui.button.green.small.compact(type="submit") 回 复
